package com.dap.cms.governance.util;

import com.dap.cms.base.IBaseService;
import com.dap.cms.governance.constant.ExcutorConstant;
import com.dap.dao.BasePo;
import com.fesine.commons.entity.Result;
import com.fesine.commons.enums.ResultEnum;
import com.fesine.commons.util.ResultUtils;
import org.slf4j.Logger;

/**
 * @description: 数据持久化操作工具类
 * @author: tigerlin
 * @createTime:2018/7/29 2:12
 * @update:修改内容
 * @author: tigerlin
 * @updateTime:2018/7/29 2:12
 */
public class ExcutorUtils {

    public static Result getResult(String opType, IBaseService service, BasePo po, Logger logger) {
        if (opType.equals(ExcutorConstant.OP_TYPE_ADD)) {
            try {
                service.save(po);
                return ResultUtils.success(ResultEnum.CREATED, null);
            } catch (Exception e) {
                logger.error("新增失败", e);
                return ResultUtils.error(500, "新增失败");
            }
        }
        if (opType.equals(ExcutorConstant.OP_TYPE_UPDATE)) {
            try {
                service.update(po);
                return ResultUtils.success(ResultEnum.CREATED, null);
            } catch (Exception e) {
                logger.error("更新失败", e);
                return ResultUtils.error(500, "更新失败");
            }
        }
        return null;
    }
}
